home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / serial / mdm-2.000 / mdm-2 / fgetstr.c < prev    next >
C/C++ Source or Header  |  1993-10-10  |  2KB  |  83 lines

  1. /*************************************************************************
  2.         Get String like FGETS but without any newlines
  3. --------------------------------------------------------------------------
  4.  
  5.     Copyright (C) 1992  Anthony Rumble
  6.  
  7.     This program is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU General Public License as published by
  9.     the Free Software Foundation; either version 1, or
  10.     any later version.
  11.  
  12.     This program is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details. <copying>
  16.  
  17.     You should have received a copy of the GNU General Public License
  18.     along with this program; if not, write to the Free Software
  19.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21. --------------------------------------------------------------------------
  22. RCS Info
  23.  
  24. $Header: /home/smilie/bbs/modem/RCS/fgetstr.c,v 1.1 1992/10/09 10:20:18 smilie Exp $
  25.  
  26. $Log: fgetstr.c,v $
  27.  * Revision 1.1  1992/10/09  10:20:18  smilie
  28.  * Initial revision
  29.  *
  30.  
  31. *************************************************************************/
  32.  
  33. /* Feature test switches */
  34. #define _POSIX_SOURCE 1
  35. #define _FGETSTR_C
  36.  
  37. /* System Headers */
  38. #include <stdio.h>
  39.  
  40. /* Local Headers */
  41.  
  42. /* Macros */
  43.  
  44. /* File scope variables */
  45.  
  46. static char fgetstr_rcsid[] = "$Id: fgetstr.c,v 1.1 1992/10/09 10:20:18 smilie Exp $";
  47. #define RCSID fgetstr_rcsid
  48.  
  49. /* External variables */
  50.  
  51. /* External Functions */
  52.  
  53. /* Structures and unions */
  54.  
  55. /* Functions */
  56.  
  57. /***************************************************************************
  58.                  FGETSTR
  59. ---------------------------------------------------------------------------
  60. Is much the same as fgets, but makes sure there isint a /n at the
  61. end of the returned string.
  62. ***************************************************************************/
  63. char *fgetstr(char *s, int n, FILE * stream)
  64. {
  65. /*------------------------------------------------------------------------*/
  66. if (!feof(stream))
  67.     {
  68.     if (fgets(s, n, stream) == NULL)
  69.         {
  70.         s[0] = 0;
  71.         return NULL;
  72.         }
  73.     else
  74.         {
  75.         if (s[strlen(s)-1] == '\n')
  76.             s[strlen(s)-1] = 0;
  77.         }
  78.     }
  79. return s;
  80. }
  81.  
  82.  
  83.